﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Httppush
{
	public partial class Flush : System.Web.UI.Page
	{

		protected void Page_Load( object sender, EventArgs e )
		{
			//string startHTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" + Environment.NewLine
			//    + "<html xmlns=\"http://www.w3.org/1999/xhtml\" >" + Environment.NewLine
			//    + "<head>" + Environment.NewLine
			//    + "<script type=\"text/javascript\" src=\"Scripts/jquery-1.4.1.min.js\"></script>" + Environment.NewLine
			//    + "</head>" + Environment.NewLine
			//    + "<body>" + Environment.NewLine;

			//startHTML += new String(' ', 1024) + Environment.NewLine;

			//Response.Write(startHTML);
			//Response.Flush();

			//string data = "<script type=\"text/javascript\">parent.$('#con').append(\"{0}\");</script>";
			//Response.Write(string.Format(data, "开始发送数据：<br/>"));
			string test="Hello World";
			byte[] bs= Encoding.Unicode.GetBytes( test );
			string s= Convert.ToBase64String( bs );
			Response.Write( s );
			Response.Write( (char)4 );
			Response.Flush();

			int index = 0;
			while (true)
			{
				System.Threading.Thread.Sleep( 2000 );
				if (index % 2 == 0)
				{
					Response.Write( s );

					//Response.Flush();
					//Response.Write(string.Format(data, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 服务端发送数据<br/>"));
				}
				else
				{
					Response.Write( (char)4 );
					//Response.Write( (char)4 );
					//Response.Write(string.Format(data, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 无数据发送<br/>"));
				}
				Response.Flush();

				index++;
			}
		}
	}
}